<?php
/**
* @package plugin itemtype for Pages-and-Items
* @version 1.0.4
* @copyright Copyright (C) 2006-2008 Carsten Engel. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* @author http://www.pages-and-items.com
* @joomla Joomla is Free Software
*/

//no direct access
if(!defined('_VALID_MOS') && !defined('_JEXEC')){
	die('Restricted access');
}

//get database
if( defined('_JEXEC') ){
	//joomla 1.5
	$database = JFactory::getDBO();
}

//get data from sub_item
$database->setQuery("SELECT * FROM #__pi_subitem_youtube WHERE item_id='$item_id' LIMIT 1");
$rows = $database->loadObjectList();
if($rows){
	$row = $rows[0];	
}
	
//check if item is restored
$restored_item = false;	
if($sub_task=='edit' && $row->id==''){
	//previously deleted item which has been restored. subitem-data has been deleted so start like new item
	$restored_item = true;	
}

//switch for new and edit
if($sub_task=='new' || $restored_item){
	//begin getting data for new item
	
	$sub_item_id = '';	
	$url = '';
	$size = '';	
	
	//end getting data for new item
}else{
	//begin getting data to edit item	
	
	$sub_item_id = $row->id;
	$url = stripslashes($row->url);
	$size = $row->size;	
		
	//end getting data to edit item
}

?>

<input type="hidden" name="sub_item_id" value="<?php echo $sub_item_id; ?>" />

<div class="pi_form_wrapper">
	<div class="left">
		<span onMouseOver="return overlib('<?php echo $pi_lang_plugin['url_tip']; ?>', CAPTION, '<?php echo $pi_lang_plugin['url']; ?>', BELOW, RIGHT);" onMouseOut="return nd();"  class="editlinktip">
			<?php echo $pi_lang_plugin['url']; ?>:
		</span>		
	</div>
	<div class="right">
		<input type="text" value="<?php echo $url; ?>" name="url" style="width: 400px;" id="youtube_video_url" />
	</div>
</div>	
<div class="pi_form_wrapper">
	<div class="left">
		<?php echo $pi_lang_plugin['size']; ?>:
	</div>
	<div class="right">
		<select name="size">
			<?php
				
				$sizes = explode(',',$pi_plugin_config['sizes']);
				for($n = 0; $n < count($sizes); $n++){
					$size_row = explode(';',$sizes[$n]);
					$size_label = $size_row[0];
					$size_value = $size_row[1];						
					echo '<option value="';
					echo $size_value;
					echo '"';
					if(($sub_task=='new' && $size_value==$pi_plugin_config['default_size']) || ($sub_task=='edit' && $size_value==$size)){
						echo 'selected="selected"';
					}
					echo '>';
					echo $size_label.' '.$size_value;
					echo '</option>';
				}


			?>			
		</select>		
	</div>
</div>
